#!/usr/bin/perl
# Maxoff stats per state
$n= @ARGV;
for ($i= 0; $i < $n; $i++)
{
    $file= $ARGV[$i];
    open FILE, $file or die "Cannot Open File '$file'\n";

    $noff{A}= 0;
    $noff{S}= 0;
    $noff{V}= 0;
    $n{A}= 0;
    $n{S}= 0;
    $n{V}= 0;
    while ($line= <FILE>)
    {
	if ($line =~ /^maxoff=(\d+)$/)
	{
	    $noff{$state}+= $1;
	}
	elsif ($line =~ /^Victory/)
	{
	    $state= 'V';
	    $n{$state}++;
	}
	elsif ($line =~ /^Stuck/)
	{
	    $state= 'S';
	    $n{$state}++;
	}
	elsif ($line =~ /^Abandoned!/)
	{
	    $state= 'A';
	    $n{$state}++;
	}
    }

    print "\n" if $i > 0;
    print qq($file\n) if $n > 1;
    print qq(Won:       $n{V} games ),
	$n{V} > 0 ? sprintf(" %.2f cards off",$noff{V}/$n{V}) : '',qq(
Lost:      $n{S} games ),
	$n{S} > 0 ? sprintf(" %.2f cards off",$noff{S}/$n{S}) : '',qq(
Abandoned: $n{A} games ),
	$n{A} > 0 ? sprintf(" %.2f cards off",$noff{A}/$n{A}) : '',qq(\n);
}
